package com.gxa.service.xiaohuoservice.Impl;

import com.gxa.common.R;
import com.gxa.mapper.xiaohuomapper.KeHuDingDanMapper;
import com.gxa.pojo.*;
import com.gxa.service.xiaohuoservice.KeHuDingDanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @version 1.0
 * @Author fluoxetine
 * @Date 2022/4/2 9:56
 **/

@Service
public class KeHuDingDanServiceImpl implements KeHuDingDanService {



    @Autowired
    private KeHuDingDanMapper keHuDingDanMapper;
//查询客户
    @Override
    public R selectKeHu(String keHuType, String keHuBianHao) {
        List<KeHu> list= keHuDingDanMapper.selectAllKeHu(keHuType,keHuBianHao);
        R r=new R();
        r.setCode(200);
        r.setMsg("查询成功");
        r.setData(list);
        return r;
    }
// 查询商品
    @Override
    public R selectShangPin(String shangPinBianHao, String shangPinMingCheng, String guiGeXingHao ,String page, String size) {
        List<ShangPin> list= keHuDingDanMapper.selectAllShangPin(shangPinBianHao, shangPinMingCheng, guiGeXingHao, page, size);
        R r=new R();
        r.setCode(200);
        r.setMsg("查询成功");
        r.setData(list);
        return r;
    }
//查询仓库
    @Override
    public R selectCangKu(String cangKeName) {
        List<CangKu> list= keHuDingDanMapper.selectCangKu(cangKeName);
        R r=new R();
        r.setCode(200);
        r.setMsg("查询成功");
        r.setData(list);
        return r;
    }
//添加客户订单
    @Override
    public R addKeHuDingDan(KeHuDingDan keHuDingDan) {
        R r = new R();
        int res= keHuDingDanMapper.addKeHuDingDan(keHuDingDan);
        r.setCode(500);
        r.setMsg("添加失败");
        if(res>0)
        {
            r.setCode(200);
            r.setMsg("添加成功");
        }
        return r;
    }
//查询所有客户订单记录
    @Override
    public R selectKeHuDingDanJiLu(String keHuName, String startTime, String endTime) {

        R r=new R();

        List list = new ArrayList();

        list= keHuDingDanMapper.selectKeHuDingDanJiLu(keHuName,startTime,endTime);
            if (list.size()!=0){
                r.setCode(200);
                r.setMsg("查询成功！");
                r.setData(list);
            }

        return r;
    }

//删除客户订单记录
    @Override
    public R delKeHuDingDanJiLuById(int id) {
        R r = new R();
        int res = keHuDingDanMapper.delKeHuDingDanJiLuById(id);
        r.setCode(500);
        r.setMsg("删除失败");
        if(res>0)
        {
            r.setCode(200);
            r.setMsg("删除成功");
        }
        return r;
    }

    @Override
    public R addShenHe(int shenHeZhuangTai) {
        R r = new R();
        int res = keHuDingDanMapper.addShenHe(shenHeZhuangTai);
        r.setCode(500);
        r.setMsg("审核失败");
        if(res>0)
        {
            r.setCode(200);
            r.setMsg("审核成功");
        }
        return r;
    }

    @Override
    public R fanShenHe(int shenHeZhuangTai) {
        R r = new R();
        int res = keHuDingDanMapper.fanShenHe(shenHeZhuangTai);
        r.setCode(500);
        r.setMsg("审核失败");
        if(res>0)
        {
            r.setCode(200);
            r.setMsg("审核成功");
        }
        return r;
    }

    @Override
    public R shenHe(int shenHeZhuangTai) {
        R r = new R();
        int res = keHuDingDanMapper.shenHe(shenHeZhuangTai);
        r.setCode(500);
        r.setMsg("审核失败");
        if(res>0)
        {
            r.setCode(200);
            r.setMsg("审核成功");
        }
        return r;
    }

    @Override
    public R updateKeHuDingDanJiLuById(KeHuDingDan keHuDingDan) {
        R r = new R();
        int res = keHuDingDanMapper.updateKeHuDingDanJiLuById(keHuDingDan);
        r.setCode(500);
        r.setMsg("更新失败");
        if(res>0)
        {
            r.setCode(200);
            r.setMsg("更新成功");
        }
        return r;
    }

}
